package com.nenglai.admin.modular.report.service.upload;

import com.nenglai.common.util.FileUtil;
import com.nenglai.model.report.entity.Template;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @author kongdehui
 * @date 2021/07/02 10:51
 **/
@Component("localUpload")
public class LocalUpload implements Upload {
    @Override
    public Object upload(MultipartFile file, String path, String filename) throws Exception {
        filename = path + "/" + filename;
        FileUtil.checkAndCreatDir(path);
        File saveFile = new File(filename);
        file.transferTo(saveFile);
        return filename;
    }

    @Override
    public File download(Template template) {
        return new File(template.getFilePath());
    }
}
